#ifndef UDPHELPER_H
#define UDPHELPER_H


#include <QMutex>
#include <QThread>
#include <QObject>

#include "content/UDPBase.h"
#include "content/BoostUdp.h"
#include "content/QUDPControl.h"


#include <memory>

namespace UDP {
    typedef enum Control_Tag{
        BOOST_MODE =(0u),
        QT_MODE ,
        TAG_ALL
    }REQUEST_MODE;
    static UDP::REQUEST_MODE current_mode = UDP::QT_MODE;
}



class UDPHelper
{
public:
    static UDPHelper* GetInstance(){
        static QMutex mutex;
        static QScopedPointer<UDPHelper> inst;
        if (Q_UNLIKELY(!inst)) {
            mutex.lock();
            if (!inst) {
                inst.reset(new UDPHelper);
            }
            mutex.unlock();
        }
        return inst.data();
    }



    /// 获取内部成员指针
    std::shared_ptr<UDPBase> p() {
        return _p_tr;
    }

private:
    static std::shared_ptr<UDPBase> _p_tr ;
    void init(){

        switch (UDP::current_mode) {
        case UDP::BOOST_MODE:
            _p_tr.reset(new BoostUdp);
            break;
        case UDP::QT_MODE:
            _p_tr.reset(new QUDPControl);
            break;
        default:
            _p_tr.reset(new UDPBase);
            break;
        }
    }

    UDPHelper(){
        init();
    }
};

#endif // UDPHELPER_H














